import json,requests

def parse_jxCom(craw_id):
    # XMN0A2793200

    headers = {
        'Accept': 'application/json, text/plain, */*',
        'Accept-Encoding': 'gzip, deflate, br',
        'Host': 'www.jx-c.com.cn',
        'Referer': 'https://www.jx-c.com.cn/weixin/wxWharfGroupSuitcase.html',
        'User-Agent ': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36',
    }

    searchC = {
        'propertyName': 'ieBlno',
        'columnName': 'IE_BLNO',
        'dataType': 'S',
        'value': craw_id,
        'operation': 'EQ',
    }
    params = {
        'operationEnvironment': 'app',
        'queryResultType': 'page',
        'searchColumns': json.dumps(searchC),
        'sum': 'false',
    }

    # https://www.jx-c.com.cn/login.html  （厦门集装箱码头）
    response = requests.get("https://www.jx-c.com.cn/xctgonline/blnoInquiries/customQuery", headers=headers,
                            params=params)
    res = json.loads(response.text)

    ## 获取费用清单
    import jsonpath
    se = jsonpath.jsonpath(response.json(), '$..ieConid')
    if se:
        ieConid = se[0]
    else:
        ieConid = ""

    se = jsonpath.jsonpath(response.json(), '$..ieDataSource')
    if se:
        ieDataSource = se[0]
    else:
        ieDataSource = ""

    if ieConid and ieDataSource:
        headers['encodeFlag']='true'

        import base64
        search_dict = [
            {"propertyName":"conid","columnName":"CONID","dataType":"S","value":ieConid,"operation":"EQ"},
            {"propertyName":"dataSource","columnName":"DATA_SOURCE","dataType":"S","value":ieDataSource,"operation":"EQ"}]
        newparams = {
            "sortDirection":str(base64.b64encode("undefined".encode('utf-8')),"utf-8"),
            "sortName":str(base64.b64encode("undefined".encode('utf-8')),"utf-8"),
            'sum': str(base64.b64encode("false".encode('utf-8')),"utf-8"),
            'searchColumns':str(base64.b64encode(json.dumps(search_dict).encode('utf-8')),"utf-8")
        }



        response = requests.get("https://www.jx-c.com.cn/xctgonline/obsDwFee/myQuery", headers=headers,
                                params=newparams)
        res1 = json.loads(response.text)
        if 'obsDwFees' in res1:
            res['obsDwFees'] = res1['obsDwFees']
        ## portfee   货物港务费
        ## addfee 港口设施安保费
        ## stackfee 堆存保管费
        ## portContract 港口作业包干费
        ## total  合计
    return res


if __name__ == '__main__':
    #XMN1A0699600 多个container

    result = parse_jxCom('XMN0A2793200')
    from pprint import pprint
    pprint(result)